<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>推送信息修改</title>
<style type="text/css">
    *{
    padding:0px;
    margn:0px;
    }
    table#stuRecordTable{width:600px;margin:40px auto;text-align: center;}
    table#stuRecordTable tr{height:30px;}
</style>
<script type="text/javascript">
    function $(eleStr){
        switch(eleStr.substr(0,1)){
        case "#":
            return document.getElementById(eleStr.substr(1));
            break;
        case ".":
            return document.getElementsByClassName(eleStr.substr(1));
            break;
        case "_":
            return document.getElementsByName(eleStr.substr(1));
            break;
        default:
            return document.getElementsByTagName(eleStr);
        break;
        }
    }

    onload = function(){

        doOperator();       
    }

    function doOperator(){

        var updates =$(".update");
        var dels =$(".del");
        for (var i = 0; i < dels.length; i++) {
            dels[i].onclick =   function(){
                if(confirm("是否确定删除？")){  
                    $("#stuRecordTable").deleteRow(this.parentNode.parentNode.rowIndex);
                }
            }
            updates[i].onclick = function(){
                var operatorCell = this.parentNode.parentNode.getElementsByTagName("td")[1]; 
                if(this.value == "修改"){
                    this.value = "确定";
                    operatorCell.innerHTML ="<input value='"+operatorCell.innerHTML+"'/>";//把内容变成文本框
                    //做修改操作
                }else{
                    operatorCell.innerHTML =operatorCell.getElementsByTagName("input")[0].value;//把文本框变成内容
                    this.value = "修改";
                    //做确定修改
                }
            }
        }
    }
    function addRow(){
        var rs = $("#stuRecordTable").rows;  //table取到所有的行
        var insertR = $("#stuRecordTable").insertRow(rs.length-1); //给表格添加一行(不包单元格)
        //insertR.innerHTML = rs[1].innerHTML;    
        var c1 = insertR.insertCell(0);       
        c1.innerHTML = "张三";
        var c2 = insertR.insertCell(1);
        c2.innerHTML = "";
        var c3 = insertR.insertCell(2);
        c3.innerHTML ='<input type="button" value="删除" class="del"/><input type="button" value="修改" class="update"/>';

        doOperator();

        var cs = rs[1].cells; //取到当前行的所有单元格
    }
</script>
</head>
<body>
    <table id="stuRecordTable" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <th>教师姓名</th> 
            <th>推送信息</th>
          	<th>编辑</th>  
          	
        </tr>
        <tr>
            <td>张三</td>
            <td>课前准备：...</td>
            <td><input type="button" value="删除" class="del"/>
            <input type="button" value="修改" class="update"/></td>
        </tr>
        <tr>
            <td colspan="3">
            <input type="button" value="添加" onclick="addRow()"/></td>
        </tr>
    </table>
    
</body>
</html>